#include "baseapplication.h"

#include <QTimer>
#include "glut.h"

#include "resourcemanager.h"

BaseApplication::BaseApplication(QWidget *parent)
	: QGLWidget(parent)
{
	mResourceManager = new ResourceManager(false);

	mFPS = 30;
	mElapsedTime = 1.f / mFPS;

	mTimer = new QTimer;
	mTimer->start(0);
	connect(mTimer, SIGNAL(timeout()), this, SLOT(AppLoopProc()));
}

BaseApplication::~BaseApplication()
{
	mTimer->stop();
	delete mTimer;

	delete mResourceManager;
}

void BaseApplication::Init()
{

}

void BaseApplication::AppLoopProc()
{
	PreUpdate();
	Update();
	PostUpdate();
}


void BaseApplication::initializeGL()
{
	Init();
}


void BaseApplication::paintGL()
{

}


void BaseApplication::resizeGL(int width, int height)
{

}


void BaseApplication::Update()
{
	
}

void BaseApplication::PreUpdate()
{
	mLastTickCount = GetTickCount();
}

void BaseApplication::PostUpdate()
{
	mElapsedTime = (GetTickCount() - mLastTickCount) / 1000.f;
}